<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<view class="content wrap">
				<u-form :model="form" ref="uForm"  :rules="rules">
					<u-form-item label="项目部" label-width="160" left-icon="home"><u-input v-model="operateName" type="select" @click="getO()"/></u-form-item>
					
					<u-form-item label="作业日期" label-width="170" left-icon="calendar"><u-input v-model="v1" type="select" @click="getT()"/></u-form-item>
					
					<u-form-item label="状态" label-width="150">
						<u-radio-group v-model="status">
							<u-radio 
								@change="radioChange" 
								v-for="(item, index) in statuslist" :key="index" 
								:name="item.name"
							>
							{{item.name}}
							</u-radio>
						</u-radio-group>
					</u-form-item>
				</u-form>
			</view>
		</view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<u-table border-color="#18b566" font-size="24">
				<u-tr>
					<u-th>类型</u-th>
					<u-th>类别</u-th>
					<u-th>用时</u-th>
					<u-th>人数</u-th>
					<u-th>总工时</u-th>
					<u-th><span style="width: 120rpx;">总量</span></u-th>
				</u-tr>
				<u-tr v-for="item in dataList" :key="item.id">
					<u-td>{{item.taskWork}}</u-td>
					
					<u-td v-if="item.v8 != '' && item.v8 != null">{{item.v8}}</u-td>
					<u-td v-else>无</u-td>
					
					<u-td v-if="item.endTime != '' && item.endTime != null">{{item.endTime}}h</u-td>
					<u-td v-else>无</u-td>
					
					<u-td v-if="item.status == '已完成'"><span class="lanse" @click="toDetailed(item.id)">{{item.peoples}}</span></u-td>
					<u-td v-else><span class="lanse" @click="toDetailed(item.id)">{{item.v6}}</span></u-td>
					
					<u-td v-if="item.hours != '' && item.hours != null"><span class="jinxingzhong" @click="taskCard(item.id)">{{item.hours}}</span></u-td>
					<u-td v-else>无</u-td>
					
					<u-td v-if="item.settlementMode == '体积'"><span style="width: 120rpx;">{{item.volume}}方</span></u-td>
					<u-td v-else-if="item.settlementMode == '数量'"><span style="width: 120rpx;">{{item.nums}}件</span></u-td>
					<u-td v-else-if="item.settlementMode == '重量'"><span style="width: 120rpx;">{{item.weights}}吨</span></u-td>
					<u-td v-else><span style="width: 120rpx;">无</span></u-td>
				</u-tr>
			</u-table>
		</view>
		<view>
			<u-select v-model="show2" :list="olist" @confirm="confirm2"></u-select>
		</view>
		<view>
			<u-calendar v-model="show3" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				dataList: [],
				flex:'',
				show3:false,
				show2:false,
				v1:"",
				olist:[],
				operateId:"",
				operateName:"",
				status:'作业中',
				statuslist: [
					{
						name: '未开始'
					},
					{
						name: '作业中'
					},
					{
						name: '已完成'
					}
				],
			}
		},
		onLoad() {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			let year = new Date().getFullYear();//年
			let month = new Date().getMonth() + 1;//注意！月份是从0月开始获取的，所以要+1;
			let day = new Date().getDate();//日
			this.v1 =  year + '-' + (month >= 10 ? month : '0' + month) + '-' + (day >= 10 ? day : '0' + day);
			
			this.$http.post('/rest/operate/list',{
			},{
				params: {},
				header: {
					'Authorization' :uni.getStorageSync('token'),
				}
			}).then(res => {
				this.operateId = res.data.data[0].id
				this.operateName = res.data.data[0].operateName
				for(let item1 of res.data.data) {
					let obj = {}
					obj.value = item1.id
					obj.label = item1.operateName
					this.olist.push(obj)
				}
			})
			setTimeout(() => {
				this.refresh()
			}, 600)
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				this.status = e
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
			getO(){
				this.show2 = true
			},
			getT(){
				this.show3 = true
			},
			confirm2(e) {
				this.operateId = e[0].value
				this.operateName = e[0].label
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
			change(e) {
				this.v1 = e.result
				console.log(e);
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
			toDetailed(e){
				this.$Router.push({ 
					name: 'taskdetailed',
					params: { taskid:e },
				})
			},
		    taskCard(e){
				this.$Router.push({ 
					name: 'taskCard',
					params: { taskid:e },
				})
		    },
			refresh(){
				this.$http.post('/rest/task/taskreport',{
				},{
					params: {v1:this.v1,operateId:this.operateId,status:this.status},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
				})
			},
		},
	}
</script>
